home *** CD-ROM | disk | FTP | other *** search
- unit HVEST;
- //
- // Exceptional Stack Tracing
- //
- // Written by Hallvard Vassbotn, September 1999
- //
- interface
-
- var
- ESTEnabled: boolean = true;
- ESTRaw : boolean = false;
-
- implementation
-
- uses
- HVExceptNotify,
- Windows,
- SysUtils,
- HVYAST32,
- HVHookDLL;
-
- {$W+} // Must have stack frames on for this code
-
- var
- OldExceptNotify: TExceptNotify;
-
- procedure NotifyException(ExceptObj: TObject; ExceptAddr: pointer; OSException: boolean);
- const
- Recursive: boolean = false;
- var
- IgnoreLevels: integer;
- FirstCaller : pointer;
- begin
- // We have to be careful what we are doing in here -
- // if an exception is raised, we could get endless recursive behaviour
- if not Recursive then
- begin
- Recursive := true;
-
- // Ignore 3 levels for frame-based tracing, 5 levels for raw tracing
- IgnoreLevels := 3;
- if ESTRaw then
- IgnoreLevels := 5;
-
- // Explicitly add the exception address to the stack trace if this
- // is an OS type exception - the address is not on the stack
- FirstCaller := nil;
- if OSException then
- FirstCaller := ExceptAddr;
-
- // Now save the stack trace to the global StackDump array
- SaveStackTrace(ESTRaw, IgnoreLevels, FirstCaller);
-
- // Chain back to any old ExceptionNotify hooks
- if Assigned(OldExceptNotify) then
- OldExceptNotify(ExceptObj, ExceptAddr, OSException);
-
- // We're home safe
- Recursive := false;
- end;
- end;
-
- initialization
- OldExceptNotify := HVExceptNotify.ExceptNotify;
- HVExceptNotify.ExceptNotify := NotifyException;
-
- finalization
- HVExceptNotify.ExceptNotify := OldNotifyException;
- OldExceptNotify := nil;
-
- end.
-
-